package chapter06._02_Lamba;

import javax.swing.*;
import java.util.Arrays;

/**
 * @Version:
 * @Description: 方法引用的学习
 * @LastDate: 2020/9/28
 */
public class MethodReference {
    private int id;

    public MethodReference(int id) {
        this.id = id;
    }

    public static void main(String[] args) {
        //Understand through an example
        var t = new Timer(1000, System.out::println);

        //当lamba表达式只有调用方法这一个操作时，就可以转换成方法引用
        MethodReference[] arr = new MethodReference[]{new MethodReference(8), new MethodReference(5), new MethodReference(90)};
        //Arrays.sort(arr, (a, b)->{return a.id - b.id});//普通lamba表达式
        Arrays.sort(arr, MethodReference::cmp);//转换成方法引用
    }

    public static int cmp(MethodReference a, MethodReference b) {
        return a.id - b.id;
    }
}
